#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Stack {
    int data;
    struct Stack* next;
};
struct Stack* top = NULL;
void push(int value)
{
    struct Stack* newNode = (struct Stack*)malloc(sizeof(struct Stack));
    newNode->data = value;
    newNode->next = top;
    top=newNode;
}
int pop()
{
    if (top == NULL)
    {
        printf("empty\n");
        return -1;
    }
    int value = top->data;
    struct Stack* temp = top;
    top = top->next;
    free(temp);
    return value;
}
int main()
{
    int N;
    scanf("%d", &N);
    while (N--)
    {
        char str[50];
        scanf("%s", str);
        if (strcmp(str, "pop") == 0)
        {
            int value = pop();
            if (value != -1)
            {
                printf("%d\n", value);
            }
        }
        else if (strcmp(str, "push") == 0)
        {
            int value;
            scanf("%d", &value);
            push(value);
        }
    }
    return 0;
}